<?php
define("EW_PAGE_ID", "list", TRUE); // Page ID
define("EW_TABLE_NAME", 'osj-user_level_permissions', TRUE);
?>
<?php 
session_start(); // Initialize session data
ob_start(); // Turn on output buffering
?>
<?php include "osj-ewcfg50.php" ?>
<?php include "osj-ewmysql50.php" ?>
<?php include "osj-phpfn50.php" ?>
<?php include "osj-osj2duser_level_permissionsinfo.php" ?>
<?php include "osj-userfn50.php" ?>
<?php include "osj-osj2dusersinfo.php" ?>
<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // Always modified
header("Cache-Control: private, no-store, no-cache, must-revalidate"); // HTTP/1.1 
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); // HTTP/1.0
?>
<?php

// Open connection to the database
$conn = ew_Connect();
?>
<?php
$Security = new cAdvancedSecurity();
?>
<?php
if (!$Security->IsLoggedIn()) $Security->AutoLogin();
$Security->LoadCurrentUserLevel('osj-user_level_permissions');
if (!$Security->CanAdmin()) {
	$Security->SaveLastUrl();
	Page_Terminate("osj-login.php");
}
?>
<?php

// Common page loading event (in userfn*.php)
Page_Loading();
?>
<?php

// Page load event, used in current page
Page_Load();
?>
<?php
$osj2Duser_level_permissions->Export = @$_GET["export"]; // Get export parameter
$sExport = $osj2Duser_level_permissions->Export; // Get export parameter, used in header
$sExportFile = $osj2Duser_level_permissions->TableVar; // Get export file, used in header
?>
<?php
if ($osj2Duser_level_permissions->Export == "html") {

	// Printer friendly, no action required
}
if ($osj2Duser_level_permissions->Export == "xml") {
	header('Content-Type: text/xml');
	header('Content-Disposition: attachment; filename=' . $sExportFile .'.xml');
}
if ($osj2Duser_level_permissions->Export == "csv") {
	header('Content-Type: application/csv');
	header('Content-Disposition: attachment; filename=' . $sExportFile .'.csv');
}
?>
<?php

// Paging variables
$nStartRec = 0; // Start record index
$nStopRec = 0; // Stop record index
$nTotalRecs = 0; // Total number of records
$nDisplayRecs = 10;
$nRecRange = 10;
$nRecCount = 0; // Record count

// Search filters
$sSrchAdvanced = ""; // Advanced search filter
$sSrchBasic = ""; // Basic search filter
$sSrchWhere = ""; // Search where clause
$sFilter = "";

// Master/Detail
$sDbMasterFilter = ""; // Master filter
$sDbDetailFilter = ""; // Detail filter
$sSqlMaster = ""; // Sql for master record

// Set up records per page dynamically
SetUpDisplayRecs();

// Handle reset command
ResetCmd();

// Check QueryString parameters
if (@$_GET["a"] <> "") {
	$osj2Duser_level_permissions->CurrentAction = $_GET["a"];

	// Clear inline mode
	if ($osj2Duser_level_permissions->CurrentAction == "cancel") {
		ClearInlineMode();
	}

	// Switch to inline edit mode
	if ($osj2Duser_level_permissions->CurrentAction == "edit") {
		InlineEditMode();
	}
} else {

	// Create form object
	$objForm = new cFormObj;
	if (@$_POST["a_list"] <> "") {
		$osj2Duser_level_permissions->CurrentAction = $_POST["a_list"]; // Get action

		// Inline Update
		if ($osj2Duser_level_permissions->CurrentAction == "update" && @$_SESSION[EW_SESSION_INLINE_MODE] == "edit") {
			InlineUpdate();
		}
	}
}

// Build filter
$sFilter = "";
if (!$Security->CanList()) {
	$sFilter = "(0=1)"; // Filter all records
}
if ($sDbDetailFilter <> "") {
	if ($sFilter <> "") $sFilter .= " AND ";
	$sFilter .= "(" . $sDbDetailFilter . ")";
}
if ($sSrchWhere <> "") {
	if ($sFilter <> "") $sFilter .= " AND ";
	$sFilter .= "(" . $sSrchWhere . ")";
}

// Set up filter in Session
$osj2Duser_level_permissions->setSessionWhere($sFilter);
$osj2Duser_level_permissions->CurrentFilter = "";

// Set Up Sorting Order
SetUpSortOrder();

// Export data only
if ($osj2Duser_level_permissions->Export == "xml" || $osj2Duser_level_permissions->Export == "csv") {
	ExportData();
	Page_Terminate(); // Terminate response
}

// Set Return Url
$osj2Duser_level_permissions->setReturnUrl("osj-osj2duser_level_permissionslist.php");
?>
<?php include "osj-header.php" ?>
<?php if ($osj2Duser_level_permissions->Export == "") { ?>
<script type="text/javascript">
<!--
var EW_PAGE_ID = "list"; // Page id
var EW_SHOW_HIGHLIGHT = "Show highlight"; 
var EW_HIDE_HIGHLIGHT = "Hide highlight";

//-->
</script>
<script type="text/javascript">
<!--

function ew_ValidateForm(fobj) {
	if (fobj.a_confirm && fobj.a_confirm.value == "F")
		return true;
	var i, elm, aelm, infix;
	var rowcnt = (fobj.key_count) ? Number(fobj.key_count.value) : 1;
	for (i=0; i<rowcnt; i++) {
		infix = (fobj.key_count) ? String(i+1) : "";
		elm = fobj.elements["x" + infix + "_user_level_table_name"];
		if (elm && !ew_HasValue(elm)) {
			if (!ew_OnError(elm, "Please enter required field - Permission To Do..."))
				return false;
		}
		elm = fobj.elements["x" + infix + "_user_level_permission"];
		if (elm && !ew_HasValue(elm)) {
			if (!ew_OnError(elm, "Please enter required field - Permission Level"))
				return false;
		}
	}
	return true;
}

//-->
</script>
<script type="text/javascript">
<!--
var firstrowoffset = 1; // First data row start at
var lastrowoffset = 0; // Last data row end at
var EW_LIST_TABLE_NAME = 'ewlistmain'; // Table name for list page
var rowclass = 'ewTableRow'; // Row class
var rowaltclass = 'ewTableAltRow'; // Row alternate class
var rowmoverclass = 'ewTableHighlightRow'; // Row mouse over class
var rowselectedclass = 'ewTableSelectRow'; // Row selected class
var roweditclass = 'ewTableEditRow'; // Row edit class

//-->
</script>
<script type="text/javascript">
<!--
var ew_DHTMLEditors = [];

//-->
</script>
<script type="text/javascript">
<!--

// js for Popup Calendar
//-->

</script>
<script type="text/javascript">
<!--

function ew_SelectKey(elem) {
	var f = elem.form;	
	if (!f.elements["key_m[]"]) return;
	if (f.elements["key_m[]"][0]) {
		for (var i=0; i<f.elements["key_m[]"].length; i++)
			f.elements["key_m[]"][i].checked = elem.checked;	
	} else {
		f.elements["key_m[]"].checked = elem.checked;	
	}
	ew_ClickAll(elem);
}

function ew_Selected(f) {
	if (!f.elements["key_m[]"]) return false;
	if (f.elements["key_m[]"][0]) {
		for (var i=0; i<f.elements["key_m[]"].length; i++)
			if (f.elements["key_m[]"][i].checked) return true;
	} else {
		return f.elements["key_m[]"].checked;
	}
	return false;
}

//-->
</script>
<script language="JavaScript" type="text/javascript">
<!--

// Write your client script here, no need to add script tags.
// To include another .js script, use:
// ew_ClientScriptInclude("my_javascript.js"); 
//-->

</script>
<?php } ?>
<?php if ($osj2Duser_level_permissions->Export == "") { ?>
<?php } ?>
<?php

// Load recordset
$bExportAll = (defined("EW_EXPORT_ALL") && $osj2Duser_level_permissions->Export <> "");
$bSelectLimit = ($osj2Duser_level_permissions->Export == "" && $osj2Duser_level_permissions->SelectLimit);
if (!$bSelectLimit) $rs = LoadRecordset();
$nTotalRecs = ($bSelectLimit) ? $osj2Duser_level_permissions->SelectRecordCount() : $rs->RecordCount();
$nStartRec = 1;
if ($nDisplayRecs <= 0) $nDisplayRecs = $nTotalRecs; // Display all records
if (!$bExportAll) SetUpStartRec(); // Set up start record position
if ($bSelectLimit) $rs = LoadRecordset($nStartRec-1, $nDisplayRecs);
?>
<p><span class="phpmaker" style="white-space: nowrap;">TABLE: User Permissions
<?php if ($osj2Duser_level_permissions->Export == "") { ?>
&nbsp;&nbsp;<a href="osj-osj2duser_level_permissionslist.php?export=html">Printer Friendly</a>
&nbsp;&nbsp;<a href="osj-osj2duser_level_permissionslist.php?export=xml">Export to XML</a>
&nbsp;&nbsp;<a href="osj-osj2duser_level_permissionslist.php?export=csv">Export to CSV</a>
<?php } ?>
</span></p>
<?php if ($osj2Duser_level_permissions->Export == "") { ?>
<?php } ?>
<?php
if (@$_SESSION[EW_SESSION_MESSAGE] <> "") {
?>
<p><span class="ewmsg"><?php echo $_SESSION[EW_SESSION_MESSAGE] ?></span></p>
<?php
	$_SESSION[EW_SESSION_MESSAGE] = ""; // Clear message
}
?>
<?php if ($osj2Duser_level_permissions->Export == "") { ?>
<form action="osj-osj2duser_level_permissionslist.php" name="ewpagerform" id="ewpagerform">
<table border="0" cellspacing="0" cellpadding="0">
	<tr>
		<td nowrap>
<span class="phpmaker">
<?php if (!isset($Pager)) $Pager = new cNumericPager($nStartRec, $nDisplayRecs, $nTotalRecs, $nRecRange) ?>
<?php if ($Pager->RecordCount > 0) { ?>
	<?php if ($Pager->FirstButton->Enabled) { ?>
	<a href="osj-osj2duser_level_permissionslist.php?start=<?php echo $Pager->FirstButton->Start ?>"><b>First</b></a>&nbsp;
	<?php } ?>
	<?php if ($Pager->PrevButton->Enabled) { ?>
	<a href="osj-osj2duser_level_permissionslist.php?start=<?php echo $Pager->PrevButton->Start ?>"><b>Previous</b></a>&nbsp;
	<?php } ?>
	<?php foreach ($Pager->Items as $PagerItem) { ?>
		<?php if ($PagerItem->Enabled) { ?><a href="osj-osj2duser_level_permissionslist.php?start=<?php echo $PagerItem->Start ?>"><?php } ?><b><?php echo $PagerItem->Text ?></b><?php if ($PagerItem->Enabled) { ?></a><?php } ?>&nbsp;
	<?php } ?>
	<?php if ($Pager->NextButton->Enabled) { ?>
	<a href="osj-osj2duser_level_permissionslist.php?start=<?php echo $Pager->NextButton->Start ?>"><b>Next</b></a>&nbsp;
	<?php } ?>
	<?php if ($Pager->LastButton->Enabled) { ?>
	<a href="osj-osj2duser_level_permissionslist.php?start=<?php echo $Pager->LastButton->Start ?>"><b>Last</b></a>&nbsp;
	<?php } ?>
	<?php if ($Pager->ButtonCount > 0) { ?><br><?php } ?>
	Records <?php echo $Pager->FromIndex ?> to <?php echo $Pager->ToIndex ?> of <?php echo $Pager->RecordCount ?>
<?php } else { ?>	
	<?php if ($Security->CanList()) { ?>
	<?php if ($sSrchWhere == "0=101") { ?>
	Please enter search criteria
	<?php } else { ?>
	No records found
	<?php } ?>
	<?php } else { ?>
	You do not have the right permission to view the page
	<?php } ?>
<?php } ?>
</span>
		</td>
<?php if ($nTotalRecs > 0) { ?>
		<td nowrap>&nbsp;&nbsp;&nbsp;&nbsp;</td>
		<td align="right" valign="top" nowrap><span class="phpmaker">Records Per Page&nbsp;
<select name="<?php echo EW_TABLE_REC_PER_PAGE ?>" id="<?php echo EW_TABLE_REC_PER_PAGE ?>" onChange="this.form.submit();" class="phpmaker">
<option value="10"<?php if ($nDisplayRecs == 10) echo " selected" ?>>10</option>
<option value="20"<?php if ($nDisplayRecs == 20) echo " selected" ?>>20</option>
<option value="50"<?php if ($nDisplayRecs == 50) echo " selected" ?>>50</option>
</select>
		</span></td>
<?php } ?>
	</tr>
</table>
</form>
<?php } ?>
<form name="fosj2Duser_level_permissionslist" id="fosj2Duser_level_permissionslist" action="osj-osj2duser_level_permissionslist.php" method="post">
<?php if ($osj2Duser_level_permissions->Export == "") { ?>
<table>
	<tr><td><span class="phpmaker">
<?php if ($Security->CanAdd()) { ?>
<a href="osj-osj2duser_level_permissionsadd.php">Add</a>&nbsp;&nbsp;
<?php } ?>
<?php if ($nTotalRecs > 0) { ?>
<?php if ($Security->CanDelete()) { ?>
<a href="" onClick="if (!ew_Selected(document.fosj2Duser_level_permissionslist)) alert('No records selected'); else {document.fosj2Duser_level_permissionslist.action='osj-osj2duser_level_permissionsdelete.php';document.fosj2Duser_level_permissionslist.encoding='application/x-www-form-urlencoded';document.fosj2Duser_level_permissionslist.submit();};return false;">Delete Selected Records</a>&nbsp;&nbsp;
<?php } ?>
<?php } ?>
	</span></td></tr>
</table>
<?php } ?>
<?php if ($nTotalRecs > 0) { ?>
<table id="ewlistmain" class="ewTable">
<?php
	$OptionCnt = 0;
if ($Security->CanView()) {
	$OptionCnt++; // view
}
if ($Security->CanEdit()) {
	$OptionCnt++; // edit
}
if ($Security->CanDelete()) {
	$OptionCnt++; // multi select
}
?>
	<!-- Table header -->
	<tr class="ewTableHeader">
<?php if ($osj2Duser_level_permissions->Export == "") { ?>
<?php if ($Security->CanView()) { ?>
<td nowrap>&nbsp;</td>
<?php } ?>
<?php if ($Security->CanEdit()) { ?>
<td nowrap>&nbsp;</td>
<?php } ?>
<?php if ($Security->CanDelete()) { ?>
<td nowrap><input type="checkbox" class="phpmaker" onClick="ew_SelectKey(this);"></td>
<?php } ?>
<?php } ?>
		<td valign="top">
<?php if ($osj2Duser_level_permissions->Export <> "") { ?>
Permission To Do...
<?php } else { ?>
	<a href="osj-osj2duser_level_permissionslist.php?order=<?php echo urlencode('user_level_table_name') ?>&ordertype=<?php echo $osj2Duser_level_permissions->user_level_table_name->ReverseSort() ?>">Permission To Do...<?php if ($osj2Duser_level_permissions->user_level_table_name->getSort() == "ASC") { ?><img src="images/sortup.gif" width="10" height="9" border="0"><?php } elseif ($osj2Duser_level_permissions->user_level_table_name->getSort() == "DESC") { ?><img src="images/sortdown.gif" width="10" height="9" border="0"><?php } ?></a>
<?php } ?>
		</td>
		<td valign="top">
<?php if ($osj2Duser_level_permissions->Export <> "") { ?>
Permission Level
<?php } else { ?>
	<a href="osj-osj2duser_level_permissionslist.php?order=<?php echo urlencode('user_level_permission') ?>&ordertype=<?php echo $osj2Duser_level_permissions->user_level_permission->ReverseSort() ?>">Permission Level<?php if ($osj2Duser_level_permissions->user_level_permission->getSort() == "ASC") { ?><img src="images/sortup.gif" width="10" height="9" border="0"><?php } elseif ($osj2Duser_level_permissions->user_level_permission->getSort() == "DESC") { ?><img src="images/sortdown.gif" width="10" height="9" border="0"><?php } ?></a>
<?php } ?>
		</td>
	</tr>
<?php
if (defined("EW_EXPORT_ALL") && $osj2Duser_level_permissions->Export <> "") {
	$nStopRec = $nTotalRecs;
} else {
	$nStopRec = $nStartRec + $nDisplayRecs - 1; // Set the last record to display
}
$nRecCount = $nStartRec - 1;
if (!$rs->EOF) {
	$rs->MoveFirst();
	if (!$osj2Duser_level_permissions->SelectLimit) $rs->Move($nStartRec - 1); // Move to first record directly
}
$RowCnt = 0;
$nEditRowCnt = 0;
if ($osj2Duser_level_permissions->CurrentAction == "edit") $RowIndex = 1;
while (!$rs->EOF && $nRecCount < $nStopRec) {
	$nRecCount++;
	if (intval($nRecCount) >= intval($nStartRec)) {
		$RowCnt++;

	// Init row class and style
	$osj2Duser_level_permissions->CssClass = "ewTableRow";
	$osj2Duser_level_permissions->CssStyle = "";

	// Init row event
	$osj2Duser_level_permissions->RowClientEvents = "onmouseover='ew_MouseOver(this);' onmouseout='ew_MouseOut(this);' onclick='ew_Click(this);'";

	// Display alternate color for rows
	if ($RowCnt % 2 == 0) {
		$osj2Duser_level_permissions->CssClass = "ewTableAltRow";
	}
	LoadRowValues($rs); // Load row values
	$osj2Duser_level_permissions->RowType = EW_ROWTYPE_VIEW; // Render view
	if ($osj2Duser_level_permissions->CurrentAction == "edit") {
		if (CheckInlineEditKey() && $nEditRowCnt == 0) { // Inline edit
			$osj2Duser_level_permissions->RowType = EW_ROWTYPE_EDIT; // Render edit
		}
	}
		if ($osj2Duser_level_permissions->RowType == EW_ROWTYPE_EDIT && $osj2Duser_level_permissions->EventCancelled) { // Update failed
			if ($osj2Duser_level_permissions->CurrentAction == "edit") {
				RestoreFormValues(); // Restore form values
			}
		}
		if ($osj2Duser_level_permissions->RowType == EW_ROWTYPE_EDIT) { // Edit row
			$nEditRowCnt++;
			$osj2Duser_level_permissions->CssClass = "ewTableEditRow";
			$osj2Duser_level_permissions->RowClientEvents = "onmouseover='this.edit=true;ew_MouseOver(this);' onmouseout='ew_MouseOut(this);' onclick='ew_Click(this);'";
		}
	RenderRow();
?>
	<!-- Table body -->
	<tr<?php echo $osj2Duser_level_permissions->DisplayAttributes() ?>>
<?php if ($osj2Duser_level_permissions->RowType == EW_ROWTYPE_EDIT) { ?>
<?php if ($osj2Duser_level_permissions->CurrentAction == "edit") { ?>
<td colspan="<?php echo $OptionCnt ?>" align="right"><span class="phpmaker">
<a href="" onClick="if (ew_ValidateForm(document.fosj2Duser_level_permissionslist)) document.fosj2Duser_level_permissionslist.submit();return false;">Update</a>&nbsp;<a href="osj-osj2duser_level_permissionslist.php?a=cancel">Cancel</a>
<input type="hidden" name="a_list" id="a_list" value="update">
</span></td>
<?php } ?>
<?php } else { ?>
<?php if ($osj2Duser_level_permissions->Export == "") { ?>
<?php if ($Security->CanView()) { ?>
<td nowrap><span class="phpmaker">
<a href="<?php echo $osj2Duser_level_permissions->ViewUrl() ?>">View</a>
</span></td>
<?php } ?>
<?php if ($Security->CanEdit()) { ?>
<td nowrap><span class="phpmaker">
<a href="<?php echo $osj2Duser_level_permissions->EditUrl() ?>">Edit</a><span class="ewSeparator">&nbsp;|&nbsp;</span><a href="<?php echo $osj2Duser_level_permissions->InlineEditUrl() ?>">Inline Edit</a>
</span></td>
<?php } ?>
<?php if ($Security->CanDelete()) { ?>
<td nowrap><span class="phpmaker">
<input type="checkbox" name="key_m[]" id="key_m[]" value="<?php echo ew_HtmlEncode($osj2Duser_level_permissions->user_level_id->CurrentValue . EW_COMPOSITE_KEY_SEPARATOR . $osj2Duser_level_permissions->user_level_table_name->CurrentValue) ?>" class="phpmaker" onclick='ew_ClickMultiCheckbox(this);'>
</span></td>
<?php } ?>
<?php } ?>
<?php } ?>
<?php if ($osj2Duser_level_permissions->RowType == EW_ROWTYPE_EDIT) { ?>
<input type="hidden" name="x<?php echo $RowIndex ?>_user_level_id" id="x<?php echo $RowIndex ?>_user_level_id" value="<?php echo ew_HtmlEncode($osj2Duser_level_permissions->user_level_id->CurrentValue) ?>">
<?php } ?>
		<!-- user_level_table_name -->
		<td<?php echo $osj2Duser_level_permissions->user_level_table_name->CellAttributes() ?>>
<?php if ($osj2Duser_level_permissions->RowType == EW_ROWTYPE_EDIT) { // Edit Record ?>
<div<?php echo $osj2Duser_level_permissions->user_level_table_name->ViewAttributes() ?>><?php echo $osj2Duser_level_permissions->user_level_table_name->EditValue ?></div>
<input type="hidden" name="x<?php echo $RowIndex ?>_user_level_table_name" id="x<?php echo $RowIndex ?>_user_level_table_name" value="<?php echo ew_HtmlEncode($osj2Duser_level_permissions->user_level_table_name->CurrentValue) ?>">
<?php } else { ?>
<div<?php echo $osj2Duser_level_permissions->user_level_table_name->ViewAttributes() ?>><?php echo $osj2Duser_level_permissions->user_level_table_name->ViewValue ?></div>
<?php } ?>
</td>
		<!-- user_level_permission -->
		<td<?php echo $osj2Duser_level_permissions->user_level_permission->CellAttributes() ?>>
<?php if ($osj2Duser_level_permissions->RowType == EW_ROWTYPE_EDIT) { // Edit Record ?>
<select id="x<?php echo $RowIndex ?>_user_level_permission" name="x<?php echo $RowIndex ?>_user_level_permission"<?php echo $osj2Duser_level_permissions->user_level_permission->EditAttributes() ?>>
<!--option value="">Please Select</option-->
<?php
if (is_array($osj2Duser_level_permissions->user_level_permission->EditValue)) {
	$arwrk = $osj2Duser_level_permissions->user_level_permission->EditValue;
	$rowswrk = count($arwrk);
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = (strval($osj2Duser_level_permissions->user_level_permission->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected" : "";	
?>
<option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
<?php echo $arwrk[$rowcntwrk][1] ?>
</option>
<?php
			}
}
?>
</select>
<?php } else { ?>
<div<?php echo $osj2Duser_level_permissions->user_level_permission->ViewAttributes() ?>><?php echo $osj2Duser_level_permissions->user_level_permission->ViewValue ?></div>
<?php } ?>
</td>
	</tr>
<?php if ($osj2Duser_level_permissions->RowType == EW_ROWTYPE_EDIT) { ?>
<?php } ?>
<?php
	}
	$rs->MoveNext();
}
?>
</table>
<?php if ($osj2Duser_level_permissions->Export == "") { ?>
<table>
	<tr><td><span class="phpmaker">
<?php if ($Security->CanAdd()) { ?>
<a href="osj-osj2duser_level_permissionsadd.php">Add</a>&nbsp;&nbsp;
<?php } ?>
<?php if ($nTotalRecs > 0) { ?>
<?php if ($Security->CanDelete()) { ?>
<a href="" onClick="if (!ew_Selected(document.fosj2Duser_level_permissionslist)) alert('No records selected'); else {document.fosj2Duser_level_permissionslist.action='osj-osj2duser_level_permissionsdelete.php';document.fosj2Duser_level_permissionslist.encoding='application/x-www-form-urlencoded';document.fosj2Duser_level_permissionslist.submit();};return false;">Delete Selected Records</a>&nbsp;&nbsp;
<?php } ?>
<?php } ?>
	</span></td></tr>
</table>
<?php } ?>
<?php } ?>
<?php if ($osj2Duser_level_permissions->CurrentAction == "edit") { ?>
<input type="hidden" name="key_count" id="key_count" value="<?php echo $RowIndex ?>">
<?php } ?>
</form>
<?php

// Close recordset and connection
if ($rs) $rs->Close();
?>
<?php if ($osj2Duser_level_permissions->Export == "") { ?>
<form action="osj-osj2duser_level_permissionslist.php" name="ewpagerform" id="ewpagerform">
<table border="0" cellspacing="0" cellpadding="0">
	<tr>
		<td nowrap>
<span class="phpmaker">
<?php if (!isset($Pager)) $Pager = new cNumericPager($nStartRec, $nDisplayRecs, $nTotalRecs, $nRecRange) ?>
<?php if ($Pager->RecordCount > 0) { ?>
	<?php if ($Pager->FirstButton->Enabled) { ?>
	<a href="osj-osj2duser_level_permissionslist.php?start=<?php echo $Pager->FirstButton->Start ?>"><b>First</b></a>&nbsp;
	<?php } ?>
	<?php if ($Pager->PrevButton->Enabled) { ?>
	<a href="osj-osj2duser_level_permissionslist.php?start=<?php echo $Pager->PrevButton->Start ?>"><b>Previous</b></a>&nbsp;
	<?php } ?>
	<?php foreach ($Pager->Items as $PagerItem) { ?>
		<?php if ($PagerItem->Enabled) { ?><a href="osj-osj2duser_level_permissionslist.php?start=<?php echo $PagerItem->Start ?>"><?php } ?><b><?php echo $PagerItem->Text ?></b><?php if ($PagerItem->Enabled) { ?></a><?php } ?>&nbsp;
	<?php } ?>
	<?php if ($Pager->NextButton->Enabled) { ?>
	<a href="osj-osj2duser_level_permissionslist.php?start=<?php echo $Pager->NextButton->Start ?>"><b>Next</b></a>&nbsp;
	<?php } ?>
	<?php if ($Pager->LastButton->Enabled) { ?>
	<a href="osj-osj2duser_level_permissionslist.php?start=<?php echo $Pager->LastButton->Start ?>"><b>Last</b></a>&nbsp;
	<?php } ?>
	<?php if ($Pager->ButtonCount > 0) { ?><br><?php } ?>
	Records <?php echo $Pager->FromIndex ?> to <?php echo $Pager->ToIndex ?> of <?php echo $Pager->RecordCount ?>
<?php } else { ?>	
	<?php if ($Security->CanList()) { ?>
	<?php if ($sSrchWhere == "0=101") { ?>
	Please enter search criteria
	<?php } else { ?>
	No records found
	<?php } ?>
	<?php } else { ?>
	You do not have the right permission to view the page
	<?php } ?>
<?php } ?>
</span>
		</td>
<?php if ($nTotalRecs > 0) { ?>
		<td nowrap>&nbsp;&nbsp;&nbsp;&nbsp;</td>
		<td align="right" valign="top" nowrap><span class="phpmaker">Records Per Page&nbsp;
<select name="<?php echo EW_TABLE_REC_PER_PAGE ?>" id="<?php echo EW_TABLE_REC_PER_PAGE ?>" onChange="this.form.submit();" class="phpmaker">
<option value="10"<?php if ($nDisplayRecs == 10) echo " selected" ?>>10</option>
<option value="20"<?php if ($nDisplayRecs == 20) echo " selected" ?>>20</option>
<option value="50"<?php if ($nDisplayRecs == 50) echo " selected" ?>>50</option>
</select>
		</span></td>
<?php } ?>
	</tr>
</table>
</form>
<?php } ?>
<?php if ($osj2Duser_level_permissions->Export == "") { ?>
<?php } ?>
<?php if ($osj2Duser_level_permissions->Export == "") { ?>
<script language="JavaScript" type="text/javascript">
<!--

// Write your table-specific startup script here
// document.write("page loaded");
//-->

</script>
<?php } ?>
<?php include "osj-footer.php" ?>
<?php

// If control is passed here, simply terminate the page without redirect
Page_Terminate();

// -----------------------------------------------------------------
//  Subroutine Page_Terminate
//  - called when exit page
//  - clean up connection and objects
//  - if url specified, redirect to url, otherwise end response
function Page_Terminate($url = "") {
	global $conn;

	// Page unload event, used in current page
	Page_Unload();

	// Global page unloaded event (in userfn*.php)
	Page_Unloaded();

	 // Close Connection
	$conn->Close();

	// Go to url if specified
	if ($url <> "") {
		ob_end_clean();
		header("Location: $url");
	}
	exit();
}
?>
<?php

// Set up number of records displayed per page
function SetUpDisplayRecs() {
	global $nDisplayRecs, $nStartRec, $osj2Duser_level_permissions;
	$sWrk = @$_GET[EW_TABLE_REC_PER_PAGE];
	if ($sWrk <> "") {
		if (is_numeric($sWrk)) {
			$nDisplayRecs = intval($sWrk);
		} else {
			if (strtolower($sWrk) == "all") { // Display all records
				$nDisplayRecs = -1;
			} else {
				$nDisplayRecs = 10; // Non-numeric, load default
			}
		}
		$osj2Duser_level_permissions->setRecordsPerPage($nDisplayRecs); // Save to Session

		// Reset start position
		$nStartRec = 1;
		$osj2Duser_level_permissions->setStartRecordNumber($nStartRec);
	} else {
		if ($osj2Duser_level_permissions->getRecordsPerPage() <> "") {
			$nDisplayRecs = $osj2Duser_level_permissions->getRecordsPerPage(); // Restore from Session
		} else {
			$nDisplayRecs = 10; // Load default
		}
	}
}

//  Exit out of inline mode
function ClearInlineMode() {
	global $osj2Duser_level_permissions;
	$osj2Duser_level_permissions->setKey("user_level_id", ""); // Clear inline edit key
	$osj2Duser_level_permissions->setKey("user_level_table_name", ""); // Clear inline edit key
	$osj2Duser_level_permissions->CurrentAction = ""; // Clear action
	$_SESSION[EW_SESSION_INLINE_MODE] = ""; // Clear inline mode
}

// Switch to Inline Edit Mode
function InlineEditMode() {
	global $Security, $osj2Duser_level_permissions;
	if (!$Security->CanEdit()) Page_Terminate("osj-login.php"); // Go to login page
	$bInlineEdit = TRUE;
	if (@$_GET["user_level_id"] <> "") {
		$osj2Duser_level_permissions->user_level_id->setQueryStringValue($_GET["user_level_id"]);
	} else {
		$bInlineEdit = FALSE;
	}
	if (@$_GET["user_level_table_name"] <> "") {
		$osj2Duser_level_permissions->user_level_table_name->setQueryStringValue($_GET["user_level_table_name"]);
	} else {
		$bInlineEdit = FALSE;
	}
	if ($bInlineEdit) {
		if (LoadRow()) {
			$osj2Duser_level_permissions->setKey("user_level_id", $osj2Duser_level_permissions->user_level_id->CurrentValue); // Set up inline edit key
			$osj2Duser_level_permissions->setKey("user_level_table_name", $osj2Duser_level_permissions->user_level_table_name->CurrentValue); // Set up inline edit key
			$_SESSION[EW_SESSION_INLINE_MODE] = "edit"; // Enable inline edit
		}
	}
}

// Peform update to inline edit record
function InlineUpdate() {
	global $objForm, $osj2Duser_level_permissions;
	$objForm->Index = 1; 
	LoadFormValues(); // Get form values
	if (CheckInlineEditKey()) { // Check key
		$osj2Duser_level_permissions->SendEmail = TRUE; // Send email on update success
		$bInlineUpdate = EditRow(); // Update record
	} else {
		$bInlineUpdate = FALSE;
	}
	if ($bInlineUpdate) { // Update success
		$_SESSION[EW_SESSION_MESSAGE] = "Update successful"; // Set success message
		ClearInlineMode(); // Clear inline edit mode
	} else {
		if (@$_SESSION[EW_SESSION_MESSAGE] == "") {
			$_SESSION[EW_SESSION_MESSAGE] = "Update failed"; // Set update failed message
		}
		$osj2Duser_level_permissions->EventCancelled = TRUE; // Cancel event
		$osj2Duser_level_permissions->CurrentAction = "edit"; // Stay in edit mode
	}
}

// Check inline edit key
function CheckInlineEditKey() {
	global $osj2Duser_level_permissions;

	//CheckInlineEditKey = True
	if (strval($osj2Duser_level_permissions->getKey("user_level_id")) <> strval($osj2Duser_level_permissions->user_level_id->CurrentValue)) {
		return FALSE;
	}
	if (strval($osj2Duser_level_permissions->getKey("user_level_table_name")) <> strval($osj2Duser_level_permissions->user_level_table_name->CurrentValue)) {
		return FALSE;
	}
	return TRUE;
}

// Set up Sort parameters based on Sort Links clicked
function SetUpSortOrder() {
	global $osj2Duser_level_permissions;

	// Check for an Order parameter
	if (@$_GET["order"] <> "") {
		$osj2Duser_level_permissions->CurrentOrder = ew_StripSlashes(@$_GET["order"]);
		$osj2Duser_level_permissions->CurrentOrderType = @$_GET["ordertype"];

		// Field user_level_table_name
		$osj2Duser_level_permissions->UpdateSort($osj2Duser_level_permissions->user_level_table_name);

		// Field user_level_permission
		$osj2Duser_level_permissions->UpdateSort($osj2Duser_level_permissions->user_level_permission);
		$osj2Duser_level_permissions->setStartRecordNumber(1); // Reset start position
	}
	$sOrderBy = $osj2Duser_level_permissions->getSessionOrderBy(); // Get order by from Session
	if ($sOrderBy == "") {
		if ($osj2Duser_level_permissions->SqlOrderBy() <> "") {
			$sOrderBy = $osj2Duser_level_permissions->SqlOrderBy();
			$osj2Duser_level_permissions->setSessionOrderBy($sOrderBy);
		}
	}
}

// Reset command based on querystring parameter cmd=
// - RESET: reset search parameters
// - RESETALL: reset search & master/detail parameters
// - RESETSORT: reset sort parameters
function ResetCmd() {
	global $sDbMasterFilter, $sDbDetailFilter, $nStartRec, $sOrderBy;
	global $osj2Duser_level_permissions;

	// Get reset cmd
	if (@$_GET["cmd"] <> "") {
		$sCmd = $_GET["cmd"];

		// Reset Sort Criteria
		if (strtolower($sCmd) == "resetsort") {
			$sOrderBy = "";
			$osj2Duser_level_permissions->setSessionOrderBy($sOrderBy);
			$osj2Duser_level_permissions->user_level_table_name->setSort("");
			$osj2Duser_level_permissions->user_level_permission->setSort("");
		}

		// Reset start position
		$nStartRec = 1;
		$osj2Duser_level_permissions->setStartRecordNumber($nStartRec);
	}
}
?>
<?php

// Set up Starting Record parameters based on Pager Navigation
function SetUpStartRec() {
	global $nDisplayRecs, $nStartRec, $nTotalRecs, $nPageNo, $osj2Duser_level_permissions;
	if ($nDisplayRecs == 0) return;

	// Check for a START parameter
	if (@$_GET[EW_TABLE_START_REC] <> "") {
		$nStartRec = $_GET[EW_TABLE_START_REC];
		$osj2Duser_level_permissions->setStartRecordNumber($nStartRec);
	} elseif (@$_GET[EW_TABLE_PAGE_NO] <> "") {
		$nPageNo = $_GET[EW_TABLE_PAGE_NO];
		if (is_numeric($nPageNo)) {
			$nStartRec = ($nPageNo-1)*$nDisplayRecs+1;
			if ($nStartRec <= 0) {
				$nStartRec = 1;
			} elseif ($nStartRec >= intval(($nTotalRecs-1)/$nDisplayRecs)*$nDisplayRecs+1) {
				$nStartRec = intval(($nTotalRecs-1)/$nDisplayRecs)*$nDisplayRecs+1;
			}
			$osj2Duser_level_permissions->setStartRecordNumber($nStartRec);
		} else {
			$nStartRec = $osj2Duser_level_permissions->getStartRecordNumber();
		}
	} else {
		$nStartRec = $osj2Duser_level_permissions->getStartRecordNumber();
	}

	// Check if correct start record counter
	if (!is_numeric($nStartRec) || $nStartRec == "") { // Avoid invalid start record counter
		$nStartRec = 1; // Reset start record counter
		$osj2Duser_level_permissions->setStartRecordNumber($nStartRec);
	} elseif (intval($nStartRec) > intval($nTotalRecs)) { // Avoid starting record > total records
		$nStartRec = intval(($nTotalRecs-1)/$nDisplayRecs)*$nDisplayRecs+1; // Point to last page first record
		$osj2Duser_level_permissions->setStartRecordNumber($nStartRec);
	} elseif (($nStartRec-1) % $nDisplayRecs <> 0) {
		$nStartRec = intval(($nStartRec-1)/$nDisplayRecs)*$nDisplayRecs+1; // Point to page boundary
		$osj2Duser_level_permissions->setStartRecordNumber($nStartRec);
	}
}
?>
<?php

// Load form values
function LoadFormValues() {

	// Load from form
	global $objForm, $osj2Duser_level_permissions;
	$osj2Duser_level_permissions->user_level_id->setFormValue($objForm->GetValue("x_user_level_id"));
	$osj2Duser_level_permissions->user_level_table_name->setFormValue($objForm->GetValue("x_user_level_table_name"));
	$osj2Duser_level_permissions->user_level_permission->setFormValue($objForm->GetValue("x_user_level_permission"));
}

// Restore form values
function RestoreFormValues() {
	global $osj2Duser_level_permissions;
	$osj2Duser_level_permissions->user_level_id->CurrentValue = $osj2Duser_level_permissions->user_level_id->FormValue;
	$osj2Duser_level_permissions->user_level_table_name->CurrentValue = $osj2Duser_level_permissions->user_level_table_name->FormValue;
	$osj2Duser_level_permissions->user_level_permission->CurrentValue = $osj2Duser_level_permissions->user_level_permission->FormValue;
}
?>
<?php

// Load recordset
function LoadRecordset($offset = -1, $rowcnt = -1) {
	global $conn, $osj2Duser_level_permissions;

	// Call Recordset Selecting event
	$osj2Duser_level_permissions->Recordset_Selecting($osj2Duser_level_permissions->CurrentFilter);

	// Load list page sql
	$sSql = $osj2Duser_level_permissions->SelectSQL();
	if ($offset > -1 && $rowcnt > -1) $sSql .= " LIMIT $offset, $rowcnt";

	// Load recordset
	$conn->raiseErrorFn = 'ew_ErrorFn';	
	$rs = $conn->Execute($sSql);
	$conn->raiseErrorFn = '';

	// Call Recordset Selected event
	$osj2Duser_level_permissions->Recordset_Selected($rs);
	return $rs;
}
?>
<?php

// Load row based on key values
function LoadRow() {
	global $conn, $Security, $osj2Duser_level_permissions;
	$sFilter = $osj2Duser_level_permissions->SqlKeyFilter();
	if (!is_numeric($osj2Duser_level_permissions->user_level_id->CurrentValue)) {
		return FALSE; // Invalid key, exit
	}
	$sFilter = str_replace("@user_level_id@", ew_AdjustSql($osj2Duser_level_permissions->user_level_id->CurrentValue), $sFilter); // Replace key value
	$sFilter = str_replace("@user_level_table_name@", ew_AdjustSql($osj2Duser_level_permissions->user_level_table_name->CurrentValue), $sFilter); // Replace key value

	// Call Row Selecting event
	$osj2Duser_level_permissions->Row_Selecting($sFilter);

	// Load sql based on filter
	$osj2Duser_level_permissions->CurrentFilter = $sFilter;
	$sSql = $osj2Duser_level_permissions->SQL();
	if ($rs = $conn->Execute($sSql)) {
		if ($rs->EOF) {
			$LoadRow = FALSE;
		} else {
			$LoadRow = TRUE;
			$rs->MoveFirst();
			LoadRowValues($rs); // Load row values

			// Call Row Selected event
			$osj2Duser_level_permissions->Row_Selected($rs);
		}
		$rs->Close();
	} else {
		$LoadRow = FALSE;
	}
	return $LoadRow;
}

// Load row values from recordset
function LoadRowValues(&$rs) {
	global $osj2Duser_level_permissions;
	$osj2Duser_level_permissions->user_level_id->setDbValue($rs->fields('user_level_id'));
	$osj2Duser_level_permissions->user_level_table_name->setDbValue($rs->fields('user_level_table_name'));
	$osj2Duser_level_permissions->user_level_permission->setDbValue($rs->fields('user_level_permission'));
}
?>
<?php

// Render row values based on field settings
function RenderRow() {
	global $conn, $Security, $osj2Duser_level_permissions;

	// Call Row Rendering event
	$osj2Duser_level_permissions->Row_Rendering();

	// Common render codes for all row types
	// user_level_table_name

	$osj2Duser_level_permissions->user_level_table_name->CellCssStyle = "";
	$osj2Duser_level_permissions->user_level_table_name->CellCssClass = "";

	// user_level_permission
	$osj2Duser_level_permissions->user_level_permission->CellCssStyle = "";
	$osj2Duser_level_permissions->user_level_permission->CellCssClass = "";
	if ($osj2Duser_level_permissions->RowType == EW_ROWTYPE_VIEW) { // View row

		// user_level_table_name
		if (!is_null($osj2Duser_level_permissions->user_level_table_name->CurrentValue)) {
			switch ($osj2Duser_level_permissions->user_level_table_name->CurrentValue) {
				case "osj-applications":
					$osj2Duser_level_permissions->user_level_table_name->ViewValue = "Applications";
					break;
				case "osj-applications":
					$osj2Duser_level_permissions->user_level_table_name->ViewValue = "Applications";
					break;
				case "osj-posts":
					$osj2Duser_level_permissions->user_level_table_name->ViewValue = "Postings";
					break;
				case "osj-resumes":
					$osj2Duser_level_permissions->user_level_table_name->ViewValue = "Resumes";
					break;
				case "osj-users":
					$osj2Duser_level_permissions->user_level_table_name->ViewValue = "Users";
					break;
				case "osj-user_detail":
					$osj2Duser_level_permissions->user_level_table_name->ViewValue = "User Detail Page";
					break;
				case "osj-user_level":
					$osj2Duser_level_permissions->user_level_table_name->ViewValue = "User Levels";
					break;
				case "osj-user_level_permissions":
					$osj2Duser_level_permissions->user_level_table_name->ViewValue = "User Permission Levels";
					break;
				default:
					$osj2Duser_level_permissions->user_level_table_name->ViewValue = $osj2Duser_level_permissions->user_level_table_name->CurrentValue;
			}
		} else {
			$osj2Duser_level_permissions->user_level_table_name->ViewValue = NULL;
		}
		$osj2Duser_level_permissions->user_level_table_name->CssStyle = "";
		$osj2Duser_level_permissions->user_level_table_name->CssClass = "";
		$osj2Duser_level_permissions->user_level_table_name->ViewCustomAttributes = "";

		// user_level_permission
		if (!is_null($osj2Duser_level_permissions->user_level_permission->CurrentValue)) {
			switch ($osj2Duser_level_permissions->user_level_permission->CurrentValue) {
				case "0":
					$osj2Duser_level_permissions->user_level_permission->ViewValue = "No Permission";
					break;
				case "1":
					$osj2Duser_level_permissions->user_level_permission->ViewValue = "Add Only";
					break;
				case "2":
					$osj2Duser_level_permissions->user_level_permission->ViewValue = "Delete Only";
					break;
				case "4":
					$osj2Duser_level_permissions->user_level_permission->ViewValue = "Edit Only";
					break;
				case "8":
					$osj2Duser_level_permissions->user_level_permission->ViewValue = "View Only";
					break;
				case "5":
					$osj2Duser_level_permissions->user_level_permission->ViewValue = "Add/Edit";
					break;
				case "3":
					$osj2Duser_level_permissions->user_level_permission->ViewValue = "Add/Delete";
					break;
				case "7":
					$osj2Duser_level_permissions->user_level_permission->ViewValue = "Add/Edit/Delete";
					break;
				case "6":
					$osj2Duser_level_permissions->user_level_permission->ViewValue = "Edit/Delete";
					break;
				case "9":
					$osj2Duser_level_permissions->user_level_permission->ViewValue = "View/Add";
					break;
				case "11":
					$osj2Duser_level_permissions->user_level_permission->ViewValue = "View/Add/Delete";
					break;
				case "12":
					$osj2Duser_level_permissions->user_level_permission->ViewValue = "View/Edit";
					break;
				case "10":
					$osj2Duser_level_permissions->user_level_permission->ViewValue = "View/Delete";
					break;
				case "14":
					$osj2Duser_level_permissions->user_level_permission->ViewValue = "View/Edit/Delete";
					break;
				case "13":
					$osj2Duser_level_permissions->user_level_permission->ViewValue = "View/Add/Edit";
					break;
				case "15":
					$osj2Duser_level_permissions->user_level_permission->ViewValue = "View/Add/Edit/Delete";
					break;
				default:
					$osj2Duser_level_permissions->user_level_permission->ViewValue = $osj2Duser_level_permissions->user_level_permission->CurrentValue;
			}
		} else {
			$osj2Duser_level_permissions->user_level_permission->ViewValue = NULL;
		}
		$osj2Duser_level_permissions->user_level_permission->CssStyle = "";
		$osj2Duser_level_permissions->user_level_permission->CssClass = "";
		$osj2Duser_level_permissions->user_level_permission->ViewCustomAttributes = "";

		// user_level_table_name
		$osj2Duser_level_permissions->user_level_table_name->HrefValue = "";

		// user_level_permission
		$osj2Duser_level_permissions->user_level_permission->HrefValue = "";
	} elseif ($osj2Duser_level_permissions->RowType == EW_ROWTYPE_ADD) { // Add row
	} elseif ($osj2Duser_level_permissions->RowType == EW_ROWTYPE_EDIT) { // Edit row

		// user_level_table_name
		$osj2Duser_level_permissions->user_level_table_name->EditCustomAttributes = "";
		if (!is_null($osj2Duser_level_permissions->user_level_table_name->CurrentValue)) {
			switch ($osj2Duser_level_permissions->user_level_table_name->CurrentValue) {
				case "osj-applications":
					$osj2Duser_level_permissions->user_level_table_name->EditValue = "Applications";
					break;
				case "osj-applications":
					$osj2Duser_level_permissions->user_level_table_name->EditValue = "Applications";
					break;
				case "osj-posts":
					$osj2Duser_level_permissions->user_level_table_name->EditValue = "Postings";
					break;
				case "osj-resumes":
					$osj2Duser_level_permissions->user_level_table_name->EditValue = "Resumes";
					break;
				case "osj-users":
					$osj2Duser_level_permissions->user_level_table_name->EditValue = "Users";
					break;
				case "osj-user_detail":
					$osj2Duser_level_permissions->user_level_table_name->EditValue = "User Detail Page";
					break;
				case "osj-user_level":
					$osj2Duser_level_permissions->user_level_table_name->EditValue = "User Levels";
					break;
				case "osj-user_level_permissions":
					$osj2Duser_level_permissions->user_level_table_name->EditValue = "User Permission Levels";
					break;
				default:
					$osj2Duser_level_permissions->user_level_table_name->EditValue = $osj2Duser_level_permissions->user_level_table_name->CurrentValue;
			}
		} else {
			$osj2Duser_level_permissions->user_level_table_name->EditValue = NULL;
		}
		$osj2Duser_level_permissions->user_level_table_name->CssStyle = "";
		$osj2Duser_level_permissions->user_level_table_name->CssClass = "";
		$osj2Duser_level_permissions->user_level_table_name->ViewCustomAttributes = "";

		// user_level_permission
		$osj2Duser_level_permissions->user_level_permission->EditCustomAttributes = "";
		$arwrk = array();
		$arwrk[] = array("0", "No Permission");
		$arwrk[] = array("1", "Add Only");
		$arwrk[] = array("2", "Delete Only");
		$arwrk[] = array("4", "Edit Only");
		$arwrk[] = array("8", "View Only");
		$arwrk[] = array("5", "Add/Edit");
		$arwrk[] = array("3", "Add/Delete");
		$arwrk[] = array("7", "Add/Edit/Delete");
		$arwrk[] = array("6", "Edit/Delete");
		$arwrk[] = array("9", "View/Add");
		$arwrk[] = array("11", "View/Add/Delete");
		$arwrk[] = array("12", "View/Edit");
		$arwrk[] = array("10", "View/Delete");
		$arwrk[] = array("14", "View/Edit/Delete");
		$arwrk[] = array("13", "View/Add/Edit");
		$arwrk[] = array("15", "View/Add/Edit/Delete");
		array_unshift($arwrk, array("", "Please Select"));
		$osj2Duser_level_permissions->user_level_permission->EditValue = $arwrk;
	} elseif ($osj2Duser_level_permissions->RowType == EW_ROWTYPE_SEARCH) { // Search row
	}

	// Call Row Rendered event
	$osj2Duser_level_permissions->Row_Rendered();
}
?>
<?php

// Update record based on key values
function EditRow() {
	global $conn, $Security, $osj2Duser_level_permissions;
	$sFilter = $osj2Duser_level_permissions->SqlKeyFilter();
	if (!is_numeric($osj2Duser_level_permissions->user_level_id->CurrentValue)) {
		return FALSE;
	}
	$sFilter = str_replace("@user_level_id@", ew_AdjustSql($osj2Duser_level_permissions->user_level_id->CurrentValue), $sFilter); // Replace key value
	$sFilter = str_replace("@user_level_table_name@", ew_AdjustSql($osj2Duser_level_permissions->user_level_table_name->CurrentValue), $sFilter); // Replace key value
	$osj2Duser_level_permissions->CurrentFilter = $sFilter;
	$sSql = $osj2Duser_level_permissions->SQL();
	$conn->raiseErrorFn = 'ew_ErrorFn';
	$rs = $conn->Execute($sSql);
	$conn->raiseErrorFn = '';
	if ($rs === FALSE)
		return FALSE;
	if ($rs->EOF) {
		$EditRow = FALSE; // Update Failed
	} else {

		// Save old values
		$rsold =& $rs->fields;
		$rsnew = array();

		// Field user_level_table_name
		// Field user_level_permission

		$osj2Duser_level_permissions->user_level_permission->SetDbValueDef($osj2Duser_level_permissions->user_level_permission->CurrentValue, 0);
		$rsnew['user_level_permission'] =& $osj2Duser_level_permissions->user_level_permission->DbValue;

		// Call Row Updating event
		$bUpdateRow = $osj2Duser_level_permissions->Row_Updating($rsold, $rsnew);
		if ($bUpdateRow) {
			$conn->raiseErrorFn = 'ew_ErrorFn';
			$EditRow = $conn->Execute($osj2Duser_level_permissions->UpdateSQL($rsnew));
			$conn->raiseErrorFn = '';
		} else {
			if ($osj2Duser_level_permissions->CancelMessage <> "") {
				$_SESSION[EW_SESSION_MESSAGE] = $osj2Duser_level_permissions->CancelMessage;
				$osj2Duser_level_permissions->CancelMessage = "";
			} else {
				$_SESSION[EW_SESSION_MESSAGE] = "Update cancelled";
			}
			$EditRow = FALSE;
		}
	}

	// Call Row Updated event
	if ($EditRow) {
		$osj2Duser_level_permissions->Row_Updated($rsold, $rsnew);
	}
	if ($EditRow) {
		WriteAuditTrailOnEdit($rsold, $rsnew);
	}
	$rs->Close();
	return $EditRow;
}
?>
<?php

// Export data in Xml or Csv format
function ExportData() {
	global $nTotalRecs, $nStartRec, $nStopRec, $nTotalRecs, $nDisplayRecs, $osj2Duser_level_permissions;
	$sCsvStr = "";
	$rs = LoadRecordset();
	$nTotalRecs = $rs->RecordCount();
	$nStartRec = 1;

	// Export all
	if (defined("EW_EXPORT_ALL")) {
		$nStopRec = $nTotalRecs;
	} else { // Export 1 page only
		SetUpStartRec(); // Set Up Start Record Position

		// Set the last record to display
		if ($nDisplayRecs < 0) {
			$nStopRec = $nTotalRecs;
		} else {
			$nStopRec = $nStartRec + $nDisplayRecs - 1;
		}
	}
	if ($osj2Duser_level_permissions->Export == "xml") {
		$XmlDoc = new cXMLDocument();
	}
	if ($osj2Duser_level_permissions->Export == "csv") {
		$sCsvStr .= "user_level_table_name" . ",";
		$sCsvStr .= "user_level_permission" . ",";
		$sCsvStr = substr($sCsvStr, 0, strlen($sCsvStr)-1); // Remove last comma
		$sCsvStr .= "\n";
	}

	// Move to first record directly for performance reason
	$nRecCount = $nStartRec - 1;
	if (!$rs->EOF) {
		$rs->MoveFirst();
		$rs->Move($nStartRec - 1);
	}
	while (!$rs->EOF && $nRecCount < $nStopRec) {
		$nRecCount++;
		if (intval($nRecCount) >= intval($nStartRec)) {
			LoadRowValues($rs);
			if ($osj2Duser_level_permissions->Export == "xml") {
				$XmlDoc->BeginRow();
				$XmlDoc->AddField('user_level_table_name', $osj2Duser_level_permissions->user_level_table_name->CurrentValue);
				$XmlDoc->AddField('user_level_permission', $osj2Duser_level_permissions->user_level_permission->CurrentValue);
				$XmlDoc->EndRow();
			}
			if ($osj2Duser_level_permissions->Export == "csv") {
				$sCsvStr .= '"' . str_replace('"', '""', strval($osj2Duser_level_permissions->user_level_table_name->CurrentValue)) . '",';
				$sCsvStr .= '"' . str_replace('"', '""', strval($osj2Duser_level_permissions->user_level_permission->CurrentValue)) . '",';
				$sCsvStr = substr($sCsvStr, 0, strlen($sCsvStr)-1); // Remove last comma
				$sCsvStr .= "\n";
			}
		}
		$rs->MoveNext();
	}

	// Close recordset
	$rs->Close();
	if ($osj2Duser_level_permissions->Export == "xml") {
		header("Content-Type: text/xml");
		echo $XmlDoc->XML();
	}
	if ($osj2Duser_level_permissions->Export == "csv") {
		echo $sCsvStr;
	}
}
?>
<?php

// Write Audit Trail start/end for grid update
function WriteAuditTrailDummy($typ) {
	$table = 'osj-user_level_permissions';

	// Write Audit Trail
	$filePfx = "log";
	$curDate = date("Y/m/d");
	$curTime = date("H:i:s");
	$id = ew_ScriptName();
	$user = CurrentUserID();
	$action = $typ;
	ew_WriteAuditTrail($filePfx, $curDate, $curTime, $id, $user, $action, $table, "", "", "", "");
}
?>
<?php

// Write Audit Trail (edit page)
function WriteAuditTrailOnEdit(&$rsold, &$rsnew) {
	global $osj2Duser_level_permissions;
	$table = 'osj-user_level_permissions';

	// Get key value
	$key = "";
	if ($key <> "") $key .= EW_COMPOSITE_KEY_SEPARATOR;
	$key .= $rsold['user_level_id'];
	if ($key <> "") $key .= EW_COMPOSITE_KEY_SEPARATOR;
	$key .= $rsold['user_level_table_name'];

	// Write Audit Trail
	$filePfx = "log";
	$curDate = date("Y/m/d");
	$curTime = date("H:i:s");
	$id = ew_ScriptName();
	$user = CurrentUserID();
	$action = "U";
	foreach (array_keys($rsnew) as $fldname) {
		if ($osj2Duser_level_permissions->fields[$fldname]->FldDataType <> EW_DATATYPE_BLOB) { // Ignore Blob Field
			if ($osj2Duser_level_permissions->fields[$fldname]->FldDataType == EW_DATATYPE_MEMO) { // DateTime Field
				$modified = (ew_FormatDateTime($rsold[$fldname], 0) <> ew_FormatDateTime($rsnew[$fldname], 0));
			} else {
				$modified = ($rsold[$fldname] <> $rsnew[$fldname]);
			}
			if ($modified) {
				if ($osj2Duser_level_permissions->fields[$fldname]->FldDataType == EW_DATATYPE_MEMO) { // Memo Field
					$oldvalue = "<MEMO>";
					$newvalue = "<MEMO>";
				} else {
					$oldvalue = $rsold[$fldname];
					$newvalue = $rsnew[$fldname];
				}
				ew_WriteAuditTrail($filePfx, $curDate, $curTime, $id, $user, $action, $table, $fldname, $key, $oldvalue, $newvalue);
			}
		}
	}
}
?>
<?php

// Page Load event
function Page_Load() {

	//echo "Page Load";
}

// Page Unload event
function Page_Unload() {

	//echo "Page Unload";
}
?>
